package com.atguigu.test;

import com.atguigu.bean.Boss;
import com.atguigu.config.MainConfigOfAutowired;
import com.atguigu.dao.BookDao;
import com.atguigu.service.BookService;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class IOCTest_Autowired {

    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MainConfigOfAutowired.class);

    @Test
    public void test1(){
        printBeans(context);
        System.out.println("=========");

        //BookService bookService = context.getBean(BookService.class);
        //System.out.println(bookService);

        //BookDao bookDao = (BookDao) context.getBean("bookDao");
        //System.out.println(bookDao);

        Boss boss = context.getBean(Boss.class);
        System.out.println(boss);

    }

    private void printBeans(ApplicationContext context) {
        String[] beanDefinitionNames = context.getBeanDefinitionNames();
        for (String beanName : beanDefinitionNames) {
            System.out.println(beanName);
        }
    }
}
